<!DOCTYPE html>
<html>
<head>
    <title>安全支付</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <script src="/js/jquery-1.11.1.js"></script>
    <script src="http://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.min.js"></script>
    <style type="text/css">
        body{padding: 0;margin:0;background-color:#1e9fff;font-family: "microsoft yahei";}
        .pay-main{background-color: #1E9FFF;padding-top: 20px;padding-left: 20px;padding-bottom: 20px;}
        .pay-main img{margin: 0 auto;display: block;}
        .pay-main .lines{margin: 0 auto;text-align: center;color:#54ff00;font-size:14pt;margin-top: 10px;}
        .tips .img{margin: 20px;}
        .tips .img img{width:20px;}
        .tips span{vertical-align: top;color:#1e9fff;padding-left: 10px;padding-top:0px;}
        .action{background:#15d447;padding: 10px 0;color:#ffffff;text-align: center;font-size:14pt;border-radius: 10px 10px; margin: 15px;}
        .action:focus{background:#4cb131;}
        .action.disabled{background-color:#aeaeae;}
        .footer{position: absolute;bottom:0;left:0;right:0;text-align: center;padding-bottom: 20px;font-size:10pt;color:#aeaeae;}
        .footer .ct-if{margin-top:6px;font-size:8pt;}
        .jieguo{top:20px;line-height:26px;max-width: 260px;padding:8px 20px;   margin: 0 auto;position: relative;border: 1px #ddd dashed;box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);}
        .text{font-size: 16px;font-weight:bold;color: #f9f900;}
    </style>
</head>
<body>
<#if errMsg??>
    <div class="conainer">
        <div class="pay-main">
            <img src="/images/pay_logo.png"/>
            <div class="lines"><span id="tips">${errMsg}</span></div>
        </div>
        <br><br><div id='appexit' class='action'>关闭页面</div>
        <div class='footer'><div class='ct-if'></div></div>
    </div>
    <script>
        $(document).ready(function () {
            $('#appexit').click(function () {
                    AlipayJSBridge.call('exitApp');
                }
            );
        });
    </script>
<#else>

    <div class="conainer">
        <div class="pay-main">
            <img src="/images/pay_logo.png"/>
            <div class="lines"><span id="tips">正在支付中...</span></div>
        </div>
        <div class="tips">
            <div class="img">
                <p></p>
            </div>
        </div>
        <br><br><div id='okpay' class='action '>确认支付</div><div class='footer'><div class='ct-if'></div></div>
        <div id='appexit' class='action' style="display:none;">关闭页面</div>
        <div class='footer'><div class='ct-if'></div></div>
    </div>
    <script  >
        var loading=6;
        var times=0;
        var addNum=0;
        var orderurl = false;
        function chaxundd() {
            times++;
            loading++;
            if(loading>6 && loading<10){
                checkOrder0();
                return;
            }
            if(loading>16){
                checkOrder();
                return;
            }
        }
        function checkOrder0(){
            loading = 0;
            $.get(
                "/api/recpay/getAliPayOrder",
                {
                    payOrderId : "${payOrderId!}",
                },
                function (result) {
                    loading=7;
                    if (result.status === '1' && addNum < 3) {
                        //AlipayJSBridge.call("pushWindow", {url: "alipays://platformapi/startapp?appId=20000186&actionType=addfriend&userId=<?php echo $userid;?>&loginId=<?php echo $account;?>&source=by_f_v&alert=true",param: {}});
                        var a = {
                            actionType: "addfriend",
                            source: "by_home",
                            userId: "${alipayUserId!}",
                            loginId: "${alipayAccount!}"
                        };
                        AlipayJSBridge.call("startApp", {
                            appId: "20000186",
                            param: a
                        }, function(a) {
                            alert("跳转失败,请扫码支付或保存二维码，使用支付宝扫一扫，从相册识别二维码支付");
                        });
                        addNum++;
                    }else if (result.status === '2') {
                        loading = 15;
                        //orderurl = 'alipays://platformapi/startapp?appId=20000090&actionType=toBillDetails&tradeNO='+result.tradeNo;
                        //window.location.href = orderurl;

                        AlipayJSBridge.call("tradePay", {
                            orderStr:'app_name="alipay"&trade_no="'+ result.tradeNo +'"&biz_type="biz_account_transfer"&invokeSource="mobilebill"'
                        }, function(result) {
                            if(result.resultCode == "9000" || result.resultCode == "8000" || result.resultCode == "6004"){
                                getStatus();
                                doGetStatusTask = setInterval(function() {
                                    getStatus();
                                }, 1500);
                                AlipayJSBridge.call('showLoading', {
                                    text: '查询支付结果...',
                                    autoHide :false,
                                    cancelable : false
                                });
                            }
                        });

                    }else if (result.status === '3') {
                        loading = 15;
                        clearInterval(queryTime);
                        $("#tips").html("下单异常，请重新下单！");
                        $("#okpay").hide();
                        $("#appexit").show();
                        AlipayJSBridge.call('hideLoading');
                    }
                }, "json");
        }
        function checkOrder() {
            loading = 10;
            $.get("/api/recpay/query",
                {
                    payOrderId : "${payOrderId!}",
                },
                function (result) {
                    loading=16;
                    if (result.status == '2' || result.status == '3') {
                        clearInterval(queryTime);
                        $("#tips").html("恭喜您,支付成功!");
                        $("#okpay").hide();
                        $("#appexit").show();
                        AlipayJSBridge.call('hideLoading');
                    }
                }, "json");
        }
        queryTime = setInterval(chaxundd, 1000);

        function tz() {
            if(orderurl){
                window.location.href = orderurl;
                return;
            }
            if(times<5){
                return;
            }
            window.location.href = "alipays://platformapi/startapp?appId=20000186&actionType=addfriend&userId=${alipayUserId!}&loginId=${alipayAccount!}&source=by_f_v&alert=true";

        }

        $(document).ready(function () {
            $('#appexit').click(function () {
                    AlipayJSBridge.call('exitApp');
                }
            );
            $('#okpay').click(function () {
                tz();
                chaxundd();
            });
        });

        function ready(a) {
            window.AlipayJSBridge ? a && a() : document.addEventListener("AlipayJSBridgeReady", a, !1);
        }

        document.addEventListener("resume", function (a) {
            checkOrder();
        });

        AlipayJSBridge.call("setTitleColor", {
            color: parseInt('1E9FFF', 16),
            reset: false // (可选,默认为false)  是否重置title颜色为默认颜色。
        });
        //导航栏loadin
        AlipayJSBridge.call('showTitleLoading');
        //副标题文字
        AlipayJSBridge.call('setTitle', {
            title: '支付收银台',
            subtitle: '安全支付'
        });
        //右上角菜单
        AlipayJSBridge.call('setOptionMenu', {
            icontype: 'filter'
        });
        AlipayJSBridge.call('showOptionMenu');
        document.addEventListener('optionMenu', function (e) {
            AlipayJSBridge.call('showPopMenu', {
                menus: [{
                    name: "查看帮助",
                    tag: "tag1"
                },
                    {
                        name: "我要投诉",
                        tag: "tag2"
                    }
                ]
            }, function (e) {
                console.log(e);
            });
        }, false);
    </script>
</#if>
</body>
</html>